package com.example.demo.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.demo.commen.R;
import com.example.demo.entity.Vacation;
import com.example.demo.entity.dto.PageQuery;
import com.example.demo.service.VacationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/vacation")
@CrossOrigin(origins = "*")
public class VacationController {

    @Autowired
    private VacationService vacationService;

    // 查询所有考勤信息
    @GetMapping
    public List<Vacation> getAllVacation() {
        return vacationService.getAllVacation();
    }

    // 根据编号查询考勤信息
    @GetMapping("/number/{number}")
    public List<Vacation> getVacationByNumber(@PathVariable int number) {
        return vacationService.getVacationByNumber(number);
    }

    // 添加考勤信息
    @PostMapping
    public boolean addVacation(@RequestBody Vacation vacation) {
        return vacationService.addVacation(vacation);
    }

    // 修改考勤信息
    @PutMapping
    public boolean updateVacation(@RequestBody Vacation vacation) {
        return vacationService.updateVacation(vacation);
    }
    @PostMapping("/page")
    public R listVacation(@RequestBody PageQuery pageQuery) {
        IPage<Vacation> result = vacationService.page(pageQuery);
        return R.ok().data("records", result.getRecords())
                .data("total", result.getTotal());
    }
}